/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2025-06-09     31603       the first version
 */

#include "getAudio.h"




//    hal_gpio_pin_afio_select(GPIOB_BASE,GPIO_PIN_5,SPI0_CLK);           //SPI的CLK
//    hal_gpio_pin_afio_select(GPIOB_BASE,GPIO_PIN_8,SPI0_MISO);          //SPI的MISO
//    hal_gpio_pin_afio_select(GPIOA_BASE,GPIO_PIN_2,ADV_TIMER_PWM0);     //PWM通道0
//    hal_gpio_pin_afio_select(GPIOA_BASE,GPIO_PIN_8,ADV_TIMER_PWM2);     //PWM通道2
//
//    hal_gpio_pin_afio_en(GPIOB_BASE,GPIO_PIN_5,HAL_ENABLE);
//    hal_gpio_pin_afio_en(GPIOB_BASE,GPIO_PIN_8,HAL_ENABLE);
//    hal_gpio_pin_afio_en(GPIOA_BASE,GPIO_PIN_2,HAL_ENABLE);
//    hal_gpio_pin_afio_en(GPIOA_BASE,GPIO_PIN_8,HAL_ENABLE);
//
//    /* 2. 配置SPI */
//    spi_init_type_def spi_init;
//    memset(&spi_init,0,sizeof(spi_init));
//
//    spi_init.spi_baud_rate_prescaler = SPI_BAUDRATEPRESCALER_2;       //设置波特率(从机此操作无影响)
//    spi_init.spi_mode      = SPI_MODE_SLAVE;                          //设置从模式
//    spi_init.spi_data_size = SPI_DATASIZE_16B;                        //设置数据16bit宽度
//    spi_init.spi_first_bit = SPI_FIRST_BIT_MSB;                       //设置帧格式为MSB
//    spi_init.spi_cpol      = SPI_CPOL_LOW;                            //设置时钟极性0
//    spi_init.spi_cpha      = SPI_CPHA_1EDGE;                          //设置时钟相位0
//    hal_spi_init(SPI0_BASE,&spi_init);                                //初始化SPI
//    hal_spi_en(SPI0_BASE,HAL_DISABLE);                                //SPI使能
//    hal_spi_ssoe_en(SPI0_BASE,HAL_DISABLE);                           //关闭CS OUTPUT
//
//    /* 初始化SPI的发送DMA */
//    dma_init_t_def dma_init;
//    memset(&dma_init,0,sizeof(dma_init));
//    dma_init.dma_mem_addr = (uint32_t)song_temp;    //设置DMA内存地址(设置音频数据地址)
//    dma_init.dma_data_num = 0;                      //设置DMA传输次数
//    dma_init.dma_dir = DMA_READ_FORM_MEM;           //设置DMA方向
//    dma_init.dma_mem_inc_en = DMA_MEM_INC_EN;       //设置DMA内存是否增长
//    dma_init.dma_p_addr = SPI0_DATA_REG;            //设置DMA外设地址
//    dma_init.dma_mem_size = DMA_MEM_SIZE_16_BIT;
//    dma_init.dma_p_size   = DMA_P_SIZE_16_BIT;
//    hal_dma_init(DMA_CH_4,&dma_init);               //初始化DMA
//
//    hal_dma_en(DMA_CH_4,HAL_DISABLE);               //DMA使能
//
//
//    adv_tim_init_t_def adv_tim_init;
//    memset(&adv_tim_init,0,sizeof(adv_tim_init));
//    adv_tim_init.adv_tim_clk_div     = 0;                           //设置时钟分频，0为不分频
//    adv_tim_init.adv_tim_load_value  = 4992 - 2;                    //设置PWM频率为8K
//    adv_tim_init.adv_tim_cmp_a_value = 4992/2 ;                     //设置通道a比较值，占空比为 50%
//    adv_tim_init.adv_tim_cmp_b_value = 4992/2 ;                     //设置通道b比较值，占空比为 50%
//    adv_tim_init.adv_tim_cnt_mode    = ADV_TIMER_CNT_MODE_INC;      //向上计数模式
//    adv_tim_init.adv_tim_cha_en      = ADV_TIMER_CHA_EN;            //使能通道a
//    hal_adv_tim_init(ADV_TIMER_0_BASE,&adv_tim_init);               //初始化TIMER0
//    hal_adv_tim_a_en(ADV_TIMER_0_BASE,HAL_DISABLE);                 //先失能TIMER0
//
//    memset(&adv_tim_init,0,sizeof(adv_tim_init));
//    adv_tim_init.adv_tim_clk_div     = 0;                           //设置时钟分频，0为不分频
//    adv_tim_init.adv_tim_load_value  = 156 - 2;                     //设置PWM频率为8*16*2K
//    adv_tim_init.adv_tim_cmp_a_value = 156/2 ;                      //设置通道a比较值，占空比为 50%
//    adv_tim_init.adv_tim_cmp_b_value = 156/2 ;                      //设置通道b比较值，占空比为 50%
//    adv_tim_init.adv_tim_cnt_mode    = ADV_TIMER_CNT_MODE_INC;      //向上计数模式
//    adv_tim_init.adv_tim_cha_en      = ADV_TIMER_CHA_EN;            //使能通道a
//    hal_adv_tim_init(ADV_TIMER_1_BASE,&adv_tim_init);               //初始化ADV_TIMER1
//    hal_adv_tim_a_en(ADV_TIMER_1_BASE,HAL_DISABLE);                 //先失能TIMER1
//
//
//    //关闭DMA，重新配置音频传输数量
//    hal_spi_en(SPI0_BASE,HAL_DISABLE);
//    hal_adv_tim_a_en(ADV_TIMER_1_BASE,HAL_DISABLE);
//    hal_adv_tim_a_en(ADV_TIMER_0_BASE,HAL_DISABLE);
//    hal_dma_en(DMA_CH_4,HAL_DISABLE);
//    hal_dma_set_data_num(DMA_CH_4,30000);
//
//    //开启DMA，开始播放音频
//    hal_dma_en(DMA_CH_4,HAL_ENABLE);
//    hal_adv_tim_a_en(ADV_TIMER_1_BASE,HAL_ENABLE);
//    hal_adv_tim_a_en(ADV_TIMER_0_BASE,HAL_ENABLE);
//    hal_spi_en(SPI0_BASE,HAL_ENABLE);
//
//    //等待播放完成，然后关闭DMA，并延时
//    while(hal_dma_get_data_num(DMA_CH_4) != 0);
//    hal_adv_tim_a_en(ADV_TIMER_0_BASE,HAL_DISABLE);
//    hal_adv_tim_a_en(ADV_TIMER_1_BASE,HAL_DISABLE);
//    OS_MsDelay(1000);



